class SQLCompilations:
    """
    Distribution center
    """

    class User:
        CHECK = "SELECT COUNT(*) as number  FROM td_user WHERE `nickname`=%s OR `email`=%s"

        GET_USER_ID = "SELECT `id` FROM td_user WHERE `id`=%s"

        GET_USER = "SELECT `id`,`nickname`,AES_DECRYPT(`password`,`salt`) AS `passwd` FROM td_user WHERE `email`=%s OR  `nickname`=%s "

        USER_STATUS = "SELECT status FROM td_user  WHERE `id`=%s AND is_del=%s"

        CREATE_USER = """INSERT INTO td_user(`id`,`nickname`,`account`,`avatar`,`email`,`gender`,`password`,`salt`,`create_time`) 
                          VALUES (%s,%s,%s,%s,%s,%s,aes_encrypt(%s,%s),%s,NOW())"""

    class Barrage:
        LIST = "SELECT `b_time`,`typef`,`color`,`author`,`b_text` FROM td_barrage WHERE video_id=%s"
        CREATE = """INSERT INTO td_barrage(`id`,`color`,`video_id`,`author`,`b_text`,`typef`,`b_time`,`create_time`)
                  VALUES (%s,%s,%s,%s,%s,%s,%s,NOW())"""

        CREATE_MANY = """INSERT INTO td_barrage(`id`,`video_id`,`b_time`,`typef`,`color`,`author`,`b_text`)
                  VALUES (%s,%s,%s,%s,%s,%s,%s)"""

    class Category:
        CREATE = """INSERT INTO td_category(`id`,`name`,`create_time`,`create_by`) VALUES (%s,%s,NOW(),'admin')"""

        GET_ONE = "SELECT `id`,`name` FROM td_category WHERE `id`=%s"

        GET_LIST = "SELECT * FROM td_category WHERE is_del=0 ORDER BY create_time DESC "

        CHECK = "SELECT COUNT(*) as number  FROM td_category WHERE `name`=%s"

        DEL = "UPDATE td_category SET `is_del`=1 WHERE id=%s"

        UPDATE = """UPDATE td_category SET `name`=%s,`update_by`='admin',`update_time`=NOW()  WHERE id=%s"""

    class Resource:
        CHECK = "SELECT COUNT(*) AS number FROM td WHERE `filename`=%s AND `is_del`=0"

        CREATE = """INSERT INTO td_source_file (`id`,`filename`,`path`,`size`,`suffix`,`create_time`)
            VALUES (%s,%s,%s,%s,%s,NOW())"""


    class Bill:
        CHECK = "SELECT COUNT(*) as number  FROM ffms.fm_bill WHERE `bill_time`=%s AND `name`=%s"
        CREATE = """INSERT INTO ffms.fm_bill(`id`,`name`,`bill_time`,`expenses_kind_id`,`payway_id`,`money`,`remark`,
                                        `create_time`,`create_by`)VALUES (%s,%s,%s,%s,%s,%s,%s,NOW(),%s)"""
        GET_LIST = """SELECT bill.*, ek.domain AS domain,ek.category AS category,pay.name AS payment_name 
                        FROM ffms.fm_bill bill 
                        LEFT JOIN  ffms.expenses_kind ek ON bill.expenses_kind_id = ek.id 
                        LEFT JOIN ffms.ffms_payment_kind pay ON bill.payway_id = pay.id
                        WHERE bill.`is_del`=0"""

        GET_PAY_LIST = "SELECT * FROM ffms_payment_kind"

        GET_ONE = "SELECT * FROM ffms.fm_bill WHERE `id`=%s AND is_del=0"

        DEL_ONE = "UPDATE ffms.fm_bill SET `is_del`=1 WHERE id=%s"

        UPDATE = """UPDATE ffms.fm_bill SET `money`=%s,`fm_type`=%s,`payway`=%s,`expenses_kind_id`=%s,
        `remark`=%s,`update_by`=%s,`update_time`=NOW()  WHERE id=%s"""

